package middleware

import (
	kdaocms "longblog/work/dao/cms"
	kutils "longblog/work/utils"
	"github.com/gin-contrib/sessions"
	"github.com/gin-gonic/gin"
)

func StoreLogRecord(c *gin.Context, msg string) {
	session := sessions.Default(c)
	userId := session.Get("user")
	userName := session.Get("user_name")
	path := c.Request.URL.Path
	if msg == "" {
		obj := kdaocms.GetCmsAdminPermissionsByPath(nil, path)
		msg = obj.Name
	}
	_, _ = kdaocms.InsertCmsAdminOptionLog(nil, kutils.AssertString(userName), kutils.AssertInt64(userId), path, c.Request.Method, msg)
}
